import { readFile, writeFile } from "node:fs/promises";
import * as path from "node:path";
import { locate } from "@iconify/json";
import { getIconsCSS } from "@iconify/utils";

/**
 * List of icons. Key is icon set prefix, value is array of icons
 * @type {Record<string, string[]>}
 */
const icons = {
  "material-symbols": ["arrow-left-rounded"],
};

// Parse each icon set
let code = "";
for (const prefix in icons) {
  // Find location of .json file
  const filename = locate(prefix);

  // Load file and parse it
  /** @type {import("@iconify/types").IconifyJSON} */
  const iconSet = JSON.parse(await readFile(filename, "utf8"));

  // Get CSS
  const css = getIconsCSS(iconSet, icons[prefix]);

  // Add it to code
  code += css;
}
const targetCSSFileDir = path.resolve(
  import.meta.dirname,
  "../src/assets/stylesheets/iconify-split.css",
);
// Save CSS file
await writeFile(targetCSSFileDir, code, "utf8");
console.log(`Saved CSS (${code.length} bytes)`);
